#ifndef _SEMAPHORE_H_
#define _SEMAPHORE_H_

#include "types.h"
#include "pthread.h"

struct semaphore {

    int max_count;
    
    int count;
  
    /* the list which is insert the suspend thread */
    list_t wait_list;

    /* spinlock for protect the semaphore */
    pthread_spinlock_t wait_lock;
};
typedef struct semaphore                 sem_t;

int sem_init (sem_t* sem, int pshared, unsigned int value);
int sem_wait (sem_t* sem);
int sem_post (sem_t* sem);

#endif
